//引入axios实例
import request from "@/utils/request"


//三级列表请求返回值每一项的类型
export interface reqCategoryItemType {
    id: number,
    name: string,
    category1Id?: number,
    category2Id?: number,
}
//三级列表请求返回值的完整的类型
export type reqCategoryReturnType = reqCategoryItemType[]
//1.一级列表请求
export const requestCategory1List = () => {
    return request.get<any, reqCategoryReturnType>(`/admin/product/getCategory1`)
}

//2.二级列表请求
export const requestCategory2List = (category1Id: number) => {
    return request.get<any, reqCategoryReturnType>(`/admin/product/getCategory2/${category1Id}`)
}

//3.三级列表请求
export const requestCategory3List = (category2Id: number) => {
    return request.get<any, reqCategoryReturnType>(`/admin/product/getCategory3/${category2Id}`)
}





/* 

    商品属性相关请求

 */
//请求商品属性列表的返回值中attrValueList的每一项类型
export interface reqAttrValueItmeType {
    id?: number,
    valueName: string,
    attrId: number,
    isEdit?: boolean
}
//请求商品属性列表的返回值中attrValueList的类型
export type reqAttrValueType = reqAttrValueItmeType[]
//请求商品属性列表的返回值每一项类型
export interface reqAttrItmType {
    id?: number,
    attrName: string,
    categoryId: number,
    categoryLevel: number,
    attrValueList: reqAttrValueType
}
//请求商品属性列表的返回值类型
export type reqAttrListType = reqAttrItmType[]
//4.请求商品属性列表
export const requestAttrList = (
    category1Id: number,
    category2Id: number,
    category3Id: number,
) => {
    return request.get<any, reqAttrListType>(`/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`)
}


//5删除某个属性
export const requestDeleteAttr = (attrId: number) => {
    return request.delete<any, null>(`/admin/product/deleteAttr/${attrId}`);
  };
  
//6.新增或修改属性
export const requestUpdateOrAddAttr = (newAttr: reqAttrItmType) => {
    return request.post<any, null>(`/admin/product/saveAttrInfo`, newAttr);
};


